<?php
/**
 * 群组数据模型
 *
 * PHP version 5
 *
 * @package   SS
 * @author    Fee <Fee@shorigo.com>
 * @copyright 2015 SRG Inc.
 */
namespace Admin\Model;
use Think\Model\RelationModel;
class AdmingroupsModel extends RelationModel {

    protected $tableName = 'sys_groups'; 
    
    /**
     * 设置主键
     *
     * @author Fee
     */
    protected $pk        = 'group_id';

    /**
     * 自动验证
     *
     * @author Fee
     */
    protected $_validate = array(
        array('group_name',   'require', '群组名称不能为空'),
        array('group_name', '', '该群组已经存在！', 0, 'unique', 1)
    );

    /**
     * 自动完成
     *
     * @author Fee
     */
    protected $_auto     = array(
            array('group_name', 'remove_xss', 3, 'function'),
            array('add_time',      'time', 1, 'function'),
            array('explain', 'remove_xss', 3, 'function'),
        );

    /**
     * 取得用于生成select的options的数组
     *
     * @return array
     * @author Fee
     */
    public function getOptions() {
        $options = array();
        $groups = $this->field('group_id,group_name,add_time')
                ->order('add_time desc')->select();
        foreach ($groups as $group) {
            $options[$group['group_id']] = $group['group_name'];
        }
        return $options;
    }
}
?>